home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
050
/
tpstuff2.arc
/
ALBUMS.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1985-10-23
|
17KB
|
565 lines
PROGRAM ALBUM_INVENTORY;
TYPE CATAGORY = (POP,ROCK,EASY_LISTENING,CLASSICAL,COUNTRY,MISCELLANEOUS);
ALBUMS = RECORD
ARTIST:STRING[40];
TITLE:STRING[50];
CAT:STRING[14];
COST:REAL;
END; (* ALBUMS *)
INVENTORY = ARRAY[1..200] OF ALBUMS;
STRNG = STRING[14];
VAR ARTIST:STRING[40];
TITLE:STRING[50];
CAT:INTEGER;
CT:INTEGER;
ALBUM:INVENTORY;
RECDAT:TEXT;
SEL:INTEGER;
NUMRECS:INTEGER;
FILEREAD:BOOLEAN;
CATSTR:STRING[14];
(****************************************************************************)
PROCEDURE ALPHABETIZE(VAR ALBUM:INVENTORY;NUMRECS:INTEGER);
VAR I,J,SMALL:INTEGER;
TEMP:ALBUMS;
BEGIN
WRITELN('ALPHABETIZING THE RECORDS.');
FOR I:=1 TO NUMRECS-1 DO
BEGIN
SMALL:=I;
FOR J:=I+1 TO NUMRECS DO
IF ALBUM[J].ARTIST < ALBUM[SMALL].ARTIST THEN
SMALL:=J;
TEMP:=ALBUM[I];
ALBUM[I]:=ALBUM[SMALL];
ALBUM[SMALL]:=TEMP;
END;
END; (* PROCEDURE ALPHABETIZE *)
(****************************************************************************)
PROCEDURE SEARCH_ARTIST(VAR ALBUM:INVENTORY;NUMRECS:INTEGER);
VAR ARTSTR:STRING[40];
CT,COUNT:INTEGER;
FOUND:BOOLEAN;
MORE:CHAR;
BEGIN
MORE:='Y';
WHILE MORE='Y' DO
BEGIN
MORE:='N';
FOUND:=FALSE;
CLRSCR;
WRITE('ENTER ARTIST''S NAME TO SEARCH FOR : ');
READLN(ARTSTR);
CLRSCR;
WRITELN('TITLES AVAILABLE BY ',ARTSTR,' ARE :');
WRITELN;
COUNT:=0;
FOR CT:=1 TO NUMRECS DO
IF POS(ARTSTR,ALBUM[CT].ARTIST)<>0 THEN
BEGIN
FOUND:=TRUE;
WRITELN('FOUND ALBUM # ',CT:3,' ',ALBUM[CT].TITLE);
WRITELN('LISTED UNDER ',ALBUM[CT].CAT);
IF ALBUM[CT].ARTIST<>ARTSTR THEN
WRITELN('ARTIST''S FULL NAME IS : ',ALBUM[CT].ARTIST);
WRITELN;
COUNT:=COUNT+1
END;
IF FOUND THEN
WRITELN('TOTAL OF ',COUNT,' ALBUMS AVAILABLE BY ',ARTSTR,'.')
ELSE
WRITELN('COULDN''T FIND ANYTHING BY ',ARTSTR,'.');
WRITELN;
WRITE('WOULD YOU LIKE TO SEARCH BY ARTIST AGAIN? Y/N : ');
READLN(MORE);
END;
END; (* PROCEDURE SEARCH_ARTIST *)
(****************************************************************************)
PROCEDURE WRITE_CATS;
BEGIN
WRITELN;
WRITELN('AVAILABLE CATAGORIES ARE :');
WRITELN;
WRITELN('1. POP');
WRITELN('2. ROCK');
WRITELN('3. JAZZ');
WRITELN('4. R & B');
WRITELN('5. COUNTRY');
WRITELN('6. CLASSICAL');
WRITELN('7. EASY LISTENING');
WRITELN('8. MISCELLANEOUS');
WRITELN
END; (* PROCEDURE WRITE_CATS *)
(****************************************************************************)
PROCEDURE GET_CATSTR(CAT:INTEGER;VAR CATSTR:STRNG);
BEGIN
CASE CAT OF
1:CATSTR:='POP';
2:CATSTR:='ROCK';
3:CATSTR:='JAZZ';
4:CATSTR:='R & B';
5:CATSTR:='COUNTRY';
6:CATSTR:='CLASSICAL';
7:CATSTR:='EASY LISTENING';
8:CATSTR:='MISCELLANEOUS';
END; (* CASE STATEMENT *)
END; (* PROCEDURE GET_CATSTR *)
(****************************************************************************)
PROCEDURE SEARCH_TITLE(VAR ALBUM:INVENTORY; NUMRECS:INTEGER);
VAR TITSTR:STRING[50];
CT,COUNT:INTEGER;
MORE:CHAR;
FOUND:BOOLEAN;
CATSTR:STRING[14];
BEGIN
MORE:='Y';
WHILE MORE='Y' DO
BEGIN
CLRSCR;
WRITE('ENTER TITLE TO SEARCH FOR : ');
READLN(TITSTR);
CLRSCR;
WRITELN('SEARCHING FOR : ',TITSTR);
WRITELN;
FOUND:=FALSE;
FOR CT:=1 TO NUMRECS DO
IF POS(TITSTR,ALBUM[CT].TITLE)<>0 THEN
BEGIN
IF TITSTR<>ALBUM[CT].TITLE THEN
BEGIN
WRITELN('FOUND ALBUM # ',CT,' FULL TITLE IS : ',ALBUM[CT].TITLE);
WRITE('AVAILABLE BY : ',ALBUM[CT].ARTIST);
WRITELN(' CATAGORY : ',ALBUM[CT].CAT);
END
ELSE
BEGIN
WRITELN('FOUND ALBUM # ',CT,' BY : ',ALBUM[CT].ARTIST);
WRITELN('CATAGORY : ',ALBUM[CT].CAT);
END;
FOUND:=TRUE;
WRITELN;
END;
IF NOT FOUND THEN
WRITELN('SORRY, I COULDN''T FIND THAT TITLE IN MY RECORDS.');
WRITELN;
WRITE('WOULD YOU LIKE TO CHECK FOR ANOTHER? Y/N : ');
READLN(MORE);
END;
END; (* PROECDURE SEARCH_TITLE *)
(****************************************************************************)
PROCEDURE SEARCH_CAT(VAR ALBUM:INVENTORY;NUMRECS:INTEGER);
VAR CT,COUNT,CAT,LIST:INTEGER;
CATSTR:STRING[14];
CHECK:BOOLEAN;
MORE:CHAR;
BEGIN
MORE:='Y';
WHILE MORE='Y' DO
BEGIN
CLRSCR;
WRITELN('CATAGORY SEARCH OPTION');
WRITE_CATS;
WRITE('ENTER THE NUMBER OF THE CATAGORY TO SEARCH FOR : ');
READLN(CAT);
COUNT:=0;
LIST:=0;
GET_CATSTR(CAT,CATSTR);
CHECK:=TRUE;
FOR CT:=1 TO NUMRECS DO
BEGIN
IF CHECK THEN
BEGIN
CHECK:=FALSE;
CLRSCR;
WRITELN('TITLES AVAILABLE IN THE ',CATSTR,' CATAGORY ARE :');
WRITELN;
END;
IF CATSTR=ALBUM[CT].CAT THEN
BEGIN
WRITELN('ALBUM # ',CT:3,' TITLE : ',ALBUM[CT].TITLE);
WRITE('AVAILABLE BY : ',ALBUM[CT].ARTIST);
WRITELN(' CATAGORY : ',CATSTR);
WRITELN;
COUNT:=COUNT+1;
LIST:=LIST+1;
CHECK:=(LIST=6);
END;
IF CHECK THEN
BEGIN
WRITELN;
WRITELN('HIT ANY KEY TO CONTINUE.');
LIST:=0;
WHILE NOT KEYPRESSED DO;
END;
END;
WRITELN;
IF LIST>=5 THEN CLRSCR;
WRITELN('THERE ARE A TOTAL OF ',COUNT,' ALBUMS IN THE ',CATSTR,' CATAGORY.');
WRITELN;
WRITE('WOULD YOU LIKE TO CHECK ANOTHER CATAGORY? Y/N : ');
READLN(MORE);
END;
END; (* PROCEDURE SEARCH_CAT *)
(****************************************************************************)
PROCEDURE SEARCH_COST(VAR ALBUM:INVENTORY;NUMRECS:INTEGER);
VAR I:INTEGER;
COST:REAL;
COUNT,CT:INTEGER;
BEGIN
CLRSCR;
WRITELN('COST SEARCH OPTION');
WRITELN;
WRITE('ENTER LOWER LIMIT OF COST FOR SEARCH : ');
READLN(COST);
CT:=1;
COUNT:=0;
WHILE CT<=NUMRECS DO
BEGIN
CLRSCR;
WRITELN('LIST OF ALBUMS WITH COST >= $',COST:1:2);
WRITELN;
FOR I:=1 TO 6 DO
BEGIN
IF CT<=NUMRECS THEN
BEGIN
IF ALBUM[CT].COST>=COST THEN
BEGIN
WRITELN('ALBUM # ',CT:3,' ALBUM TITLE : ',ALBUM[CT].TITLE);
WRITE('BY : ':11,ALBUM[CT].ARTIST);
WRITE(' CATAGORY : ',ALBUM[CT].CAT);
WRITELN(' COST : $',ALBUM[CT].COST:1:2);
WRITELN;
COUNT:=COUNT+1;
END;
CT:=CT+1;
END;
END;
WRITELN('PRESS ANY KEY TO CONTINUE');
WHILE NOT KEYPRESSED DO;
END;
IF CT>=NUMRECS THEN
BEGIN;
WRITELN('END OF LISTING:');
WRITE('TOTAL NUMBER OF ALBUMS WITH COST OVER ',COST:1:2);
WRITELN(' IS ',COUNT);
WRITELN
END;
END; (* PROCEDURE SEARCH_COST *)
(****************************************************************************)
PROCEDURE READ_FILE(VAR ALBUM:INVENTORY;VAR NUMRECS:INTEGER);
VAR I:INTEGER;
BEGIN
CLRSCR;
WRITELN('STAND-BY, READING FILE TO MEMORY.');
RESET(RECDAT);
I:=0;
WHILE NOT EOF(RECDAT) DO
BEGIN
I:=I+1;
GOTOXY(1,3);
WRITELN('READING RECORD # ',I:3);
READLN(RECDAT, ALBUM[I].ARTIST);
READLN(RECDAT, ALBUM[I].TITLE);
READLN(RECDAT, ALBUM[I].CAT);
READLN(RECDAT, ALBUM[I].COST);
END;
NUMRECS:=I;
WRITELN;
WRITELN('FILE READ INTO MEMORY.');
WRITELN('NUMBER OF RECORDS OCCUPIED IS ',NUMRECS,'.');
WRITELN;
DELAY(1000)
END; (* PROCEDURE READ_FILE *)
(****************************************************************************)
PROCEDURE ENTER_DATA(VAR ALBUM:INVENTORY;VAR NUMRECS:INTEGER);
VAR ARTSTR:STRING[40];
TITSTR:STRING[50];
CATSTR:STRING[14];
RIGHT:CHAR;
MORE:CHAR;
CATVAL:INTEGER;
COST:REAL;
BEGIN
MORE:='Y';
WHILE MORE='Y' DO
BEGIN
CLRSCR;
WRITELN('READY TO ENTER NEW RECORD INTO FILE.');
WRITELN('UPDATING RECORD NUMBER ',NUMRECS+1);
WRITELN;
RIGHT:='N';
WHILE RIGHT='N' DO
BEGIN
WRITE('ENTER THE ARTIST''S NAME : ');
READLN(ARTSTR);
WRITE('ENTER THE ALBUM TITLE : ');
READLN(TITSTR);
WRITE('ENTER THE COST : ');
READ(COST);
WRITE_CATS;
WRITE('ENTER THE CATAGORY NUMBER : ');
READLN(CATVAL);
GET_CATSTR(CATVAL,CATSTR);
WRITE('IS ALL INFORMATION CORRECT? Y/N :');
READLN(RIGHT);
WRITELN;
END;
NUMRECS:=NUMRECS+1;
ALBUM[NUMRECS].ARTIST:=ARTSTR;
ALBUM[NUMRECS].TITLE:=TITSTR;
ALBUM[NUMRECS].CAT:=CATSTR;
ALBUM[NUMRECS].COST:=COST;
WRITELN;
WRITE('ANY MORE ALBUMS TO ENTER? Y/N : ');
READLN(MORE);
END;
END; (* PROCEDURE ENTER_DATA *)
(****************************************************************************)
PROCEDURE WRITE_FILE(VAR ALBUM:INVENTORY;NUMRECS:INTEGER);
VAR I:INTEGER;
BEGIN
CLRSCR;
WRITELN('CLOSING OLD FILE');
CLOSE(RECDAT);
WRITELN('ERASING OLD FILE');
ERASE(RECDAT);
WRITELN('PREPING NEW FILE FOR WRITING');
REWRITE(RECDAT);
ALPHABETIZE(ALBUM,NUMRECS);
FOR I:=1 TO NUMRECS DO
BEGIN
GOTOXY(1,10);
WRITELN('WRITING RECORD # ',I,' TO FILE.');
WRITELN(RECDAT, ALBUM[I].ARTIST);
WRITELN(RECDAT, ALBUM[I].TITLE);
WRITELN(RECDAT, ALBUM[I].CAT);
WRITELN(RECDAT, ALBUM[I].COST);
END;
WRITELN;
WRITELN('CLOSING NEW FILE');
CLOSE(RECDAT);
WRITELN('DONE');
DELAY(1500)
END; (* PROCEDURE WRITE_FILE *)
(****************************************************************************)
PROCEDURE UPDATE_RECS(VAR ALBUM:INVENTORY;VAR NUMRECS:INTEGER);
VAR NEWFILE:CHAR;
BEGIN
{ NEWFILE:='X';
WHILE(NEWFILE<>'Y') AND (NEWFILE<>'N') DO
BEGIN
WRITE('CREATE A NEW FILE? Y/N : ');
READLN(NEWFILE);
END;
IF NEWFILE='Y' THEN
BEGIN
REWRITE(RECDAT);
CLOSE(RECDAT);
END; }
CLRSCR;
ENTER_DATA(ALBUM,NUMRECS);
WRITE_FILE(ALBUM,NUMRECS);
END; (* PROCEDURE UPDATE_RECS *)
(****************************************************************************)
PROCEDURE SEARCH_RECS(VAR ALBUM:INVENTORY;NUMRECS:INTEGER);
VAR MORE:CHAR;
SEL:INTEGER;
BEGIN
MORE:='Y';
WHILE MORE='Y' DO
BEGIN
CLRSCR;
WRITELN('INVENTORY SEARCH OPTION');
WRITELN;
WRITELN('AVAILABLE CHOICES ARE:');
WRITELN;
WRITELN('1. SEARCH BY ARTIST');
WRITELN('2. SEARCH BY TITLE');
WRITELN('3. SEARCH BY CATAGORY');
WRITELN('4. SEARCH BY COST');
WRITELN('5. EXIT TO MAIN PROGRAM');
WRITELN;
WRITE('ENTER THE NUMBER OF YOUR CHOICE : ');
READLN(SEL);
CASE SEL OF
1:SEARCH_ARTIST(ALBUM,NUMRECS);
2:SEARCH_TITLE(ALBUM,NUMRECS);
3:SEARCH_CAT(ALBUM,NUMRECS);
4:SEARCH_COST(ALBUM,NUMRECS);
END; (* CASE STATEMENT *)
WRITELN;
WRITE('WOULD YOU LIKE A SEARCH OF ANOTHER TYPE? Y/N : ');
READLN(MORE);
END;
END; (* PROCEDURE SEARCH_RECS *)
(****************************************************************************)
PROCEDURE LIST_RECS(VAR ALBUM:INVENTORY;NUMRECS:INTEGER);
VAR CT,I:INTEGER;
CAT:INTEGER;
BEGIN
CT:=1;
WHILE CT<=NUMRECS DO
BEGIN
CLRSCR;
WRITELN('LISTING OF ALBUM INVENTORY');
WRITELN;
FOR I:=1 TO 6 DO
BEGIN
IF CT<=NUMRECS THEN
BEGIN
WRITELN('ALBUM # ',CT:3,' ALBUM TITLE : ',ALBUM[CT].TITLE);
WRITE('BY : ':11,ALBUM[CT].ARTIST);
WRITELN(' CATAGORY : ',ALBUM[CT].CAT);
WRITELN;
CT:=CT+1;
END;
IF CT=NUMRECS THEN
BEGIN;
WRITELN('END OF LISTING: TOTAL COUNT IS ',NUMRECS,' ALBUMS.');
WRITELN
END;
END;
WRITELN('PRESS ANY KEY TO CONTINUE');
WHILE NOT KEYPRESSED DO;
END;
END; (* PROCEDURE LIST_RECS *)
(****************************************************************************)
PROCEDURE CHANGE_REC(VAR ALBUM:INVENTORY;NUMRECS:INTEGER);
VAR RECNUM:INTEGER;
I,J:INTEGER;
SWITCH:INTEGER;
CAT:INTEGER;
CORRECT:BOOLEAN;
ANSWER:CHAR;
MORE:CHAR;
COST:REAL;
BEGIN
MORE:='Y';
WHILE MORE='Y' DO
BEGIN
CLRSCR;
WRITELN('OPTION TO CHANGE A RECORD');
CORRECT:=FALSE;
WHILE NOT CORRECT DO
BEGIN
GOTOXY(1,3);
WRITE('ENTER THE RECORD NUMBER TO BE CHANGED : ');
READLN(RECNUM);
WRITELN;
WRITELN('CURRENT DATA IN RECORD IS AS FOLLOWS :');
WRITELN('1. ARTIST NAME : ',ALBUM[RECNUM].ARTIST);
WRITELN('2. ALBUM TITLE : ',ALBUM[RECNUM].TITLE);
WRITELN('3. CATAGORY : ',ALBUM[RECNUM].CAT);
WRITELN('4. COST : ',ALBUM[RECNUM].COST);
WRITE('ENTER THE NUMBER OF THE VALUE TO BE CHANGED : ');
READLN(SWITCH);
CASE SWITCH OF
1:BEGIN
WRITE('ENTER THE NEW ARTIST NAME : ');
READLN(ALBUM[RECNUM].ARTIST);
END;
2:BEGIN
WRITE('ENTER THE NEW ALBUM TITLE : ');
READLN(ALBUM[RECNUM].TITLE);
END;
3:BEGIN
WRITE_CATS;
WRITE('ENTER THE NEW CATAGORY NUMBER : ');
READLN(CAT);
GET_CATSTR(CAT,ALBUM[RECNUM].CAT);
END;
4:BEGIN
WRITE('ENTER THE NEW COST : ');
READLN(ALBUM[RECNUM].COST);
END;
END; (* CASE STATEMENT *)
WRITELN('UPDATED DATA IS AS FOLLOWS :');
WRITELN('ARTIST NAME : ',ALBUM[RECNUM].ARTIST);
WRITELN('ALBUM TITLE : ',ALBUM[RECNUM].TITLE);
WRITELN(' CATAGORY : ',ALBUM[RECNUM].CAT);
WRITELN;
WRITE('IS THIS CORRECT Y/N : ');
READLN(ANSWER);
CORRECT:=ANSWER='Y';
END;
WRITE('NEED TO UPDATE ANY MORE RECORDS? Y/N : ');
READLN(MORE);
END;
END; (* PROCEDURE CHANGE_REC *)
(****************************************************************************)
PROCEDURE DELETE_REC(VAR ALBUM:INVENTORY;VAR NUMRECS:INTEGER);
VAR I,J,RECNUM:INTEGER;
BEGIN
WRITELN('OPTION TO DELETE A RECORD.');
WRITELN;
WRITE('ENTER THE RECORD NUMBER TO BE DELETED : ');
READLN(RECNUM);
FOR I:=RECNUM TO NUMRECS-1 DO
ALBUM[RECNUM]:=ALBUM[RECNUM+1];
NUMRECS:=NUMRECS-1;
END; (* PROCEDURE DELETE_REC *)
(****************************************************************************)
PROCEDURE GET_COST
(VAR ALBUMS:INVENTORY;NUMRECS:INTEGER);
VAR I:INTEGER;
TOTCOST:REAL;
BEGIN
TOTCOST:=0;
FOR I:=1 TO NUMRECS DO
TOTCOST:=TOTCOST+ALBUM[I].COST;
WRITELN('TOTAL APPROXIMATE COST OF COLLECTION IS $',TOTCOST:1:2);
WRITELN;
WRITELN('HIT ANY KEY TO CONTINUE');
WHILE NOT KEYPRESSED DO;
END; (* PROCEDURE GET_COST *)
(****************************************************************************)
BEGIN (* MAIN PROGRAM *)
ASSIGN(RECDAT,'C:ALBUMS.DTA');
SEL:=0;
FILEREAD:=FALSE;
WHILE SEL<7 DO
BEGIN
SEL:=0;
CLRSCR;
IF NOT FILEREAD THEN
READ_FILE(ALBUM,NUMRECS);
FILEREAD:=TRUE;
ALPHABETIZE(ALBUM,NUMRECS);
CLRSCR;
WRITELN('ALBUM INVENTORY PROGRAM BY STEVE ROWLAND');
WRITELN('WRITTEN IN TURBO PASCAL JULY 1984');
WRITELN;
WRITELN('AVAILABLE OPTIONS ARE :');
WRITELN;
WRITELN('1. UPDATE THE INVENTORY');
WRITELN('2. SEARCH THE INVENTORY');
WRITELN('3. LIST THE INVENTORY TO THE PRINTER');
WRITELN('4. CHANGE A RECORD IN THE INVENTORY');
WRITELN('5. DELETE A RECORD IN THE INVENTORY');
WRITELN('6. FIND APPROXIMATE COST OF INVENTORY');
WRITELN('7. END THE PROGRAM AND RETURN TO THE SYSTEM');
WRITELN;
WHILE (SEL<1) OR (SEL>7) DO
BEGIN
WRITE('ENTER THE NUMBER OF YOUR SELECTION : ');
READLN(SEL);
IF (SEL<1) OR (SEL>7) THEN
WRITE(#7);
END;
CASE SEL OF
1:UPDATE_RECS(ALBUM,NUMRECS);
2:SEARCH_RECS(ALBUM,NUMRECS);
3:LIST_RECS(ALBUM,NUMRECS);
4:CHANGE_REC(ALBUM,NUMRECS);
5:DELETE_REC(ALBUM,NUMRECS);
6:GET_COST(ALBUM,NUMRECS);
END; (* CASE STATEMENT *)
END;
END.